package view;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;

/**
 * This Class is a Customer Complaint GUI which extends AbstractGUI.
 * @author Tal
 *
 */
public class CustomerCompliantGUI extends AbstractGUI
{
	private JTextArea DetailsTextArea = null;
	private JButton sendComplaintButton = null;
	private JLabel wrnMessage = null;
	private JPanel contentPane=null;
	
	/**
	 * This is Customer Complaint window Constructor.
	 */
	public CustomerCompliantGUI ()
	{ 
		 //CustomerCompliant panel
		   contentPane=new JPanel();
		   
		   contentPane.setBorder(new TitledBorder(null, "Customer Feedback", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		   
		   contentPane.setLayout(null);
		   contentPane.setOpaque(true);
		   contentPane.add(getDetailsArea());
		   contentPane.add(getSendComplaintButton());
		   contentPane.add(getWrnMessage());
		   contentPane.add(getBackButton());      
	         
	         //Frame
		        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		        this.setTitle("Customer Feedback Window");
		        this.setContentPane(contentPane);  
			    this.setLocationRelativeTo(null); //This will center the JFrame in the middle of the screen
		        this.setLocationByPlatform(true);
		        this.setSize(500, 400);
	               
	  }
		
	/**
	 * This method initializes Details Text Area	
	 */
	private JTextArea getDetailsArea() {
		if (DetailsTextArea == null) {
			DetailsTextArea = new JTextArea();
			DetailsTextArea.setBounds(new Rectangle(49, 79, 400, 130));		
			DetailsTextArea.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		}
		return DetailsTextArea;
	}
	
	/**
	 * This method initializes Send Complaint Button	
	 */
	private JButton getSendComplaintButton() {
		if (sendComplaintButton == null) {
			sendComplaintButton = new JButton();
			sendComplaintButton.setBounds(new Rectangle(76, 247, 129, 35));
			sendComplaintButton.setText("Give Feedback");		
		}
		return sendComplaintButton;
	}
	
	
	/**
	 * This method initializes Back Button	
	 */
	private JButton getBackButton() {
		if (backButton == null) {
			backButton = new JButton();
			backButton.setBounds(new Rectangle(297, 247, 129, 35));
			backButton.setText("Back to main");			
		}
		return backButton;
	}
	
	/**
	 * This method creates warning message if currently is null.
	 * @return JLabel type.
	 */
	private JLabel getWrnMessage() {
		if (wrnMessage == null) {
			wrnMessage = new JLabel();
			wrnMessage.setForeground(Color.RED);
			wrnMessage.setBounds(76, 31, 350, 26);
			wrnMessage.setVisible(false);
		}
		return wrnMessage;
	}
	
	/**
	 * Public Methods
	 * 
	 */
	
	
	/**
	 * This method adds action listener to send Complaint button.
	 * @param listener
	 */
	public void addSendComplaintActionListener(ActionListener listener){
		sendComplaintButton.addActionListener(listener);
	}
	
	/**
	 * This method return Details TextArea.
	 * @param String-details	 
	 * */
	
	public String getDetails(){
		return this.DetailsTextArea.getText();
	}
	
	/**
	 * This method display Warning Message.
	 * @param void	 
	 * */
	
	public void displayWrnMessage(String msg){
		wrnMessage.setText(msg);
		wrnMessage.setVisible(true);
	}
	
	/**
	 * This method return -simulate back button pressed .
	 * @param listener
	 */
	public void clickBackButton()
	{
		this.getBackButton().doClick();
	}

}
